<style type="text/css">
#performanceBatch span.error {
      position: absolute !important;
      left: 148px;
}
#performanceBatch tr td div {
  height: 26px;
  padding-top: 3px;
}
#performanceBatch tr td div input{
    float: left;
}
</style>
<form method="post" action="${rc.getContextPath()}/manage/performance/saveBatchPerformance" class="pageForm required-validate" onsubmit="return validateCallback(this,batchjobAjaxDone);">
    <input type="hidden" name="navTabId" value="${navTabId!''}" />
    <div class="pageFormContent">
        <fieldset>
            <dl class="notnormal">
                <dt><@label key='date.C,colon'>日期：</@label></label></dt>
                <dd>
                    <input type="text" class="required date"  name="theDate" readonly  /><a class="inputDateButton" href="javascript:;">选择</a>
                </dd>
            </dl>
            <dl class="notnormal">
                <dt><@label key="shiftingWorkCenter.C">实际工作中心：</@label></dt>
                <dd><input id="workCenter.workCenterText" class="required" type="text"  suggestFields="workCenterCode,workCenterText" postField="workCenterCode"  
                suggestUrl="${rc.getContextPath()}/manage/workCenter/workCenterSuggest?hr=hr" lookupGroup="workCenter" 
                remote="${rc.getContextPath()}/manage/workCenter/validateWorkCenter" warn="<@label key='workCenterNotExitstOrLocked.M'>工作中心不存在或已被使用</@label>" />
                <input type="hidden" name="shiftingWorkCenterCode" id="workCenter.workCenterCode" />
                </dd>
            </dl>
            <dl class="notnormal">
                <dt><@label key='materialCode.C'>物料编码：</@label></dt>
                <dd>
                    <input class="required look" id="materialLookup.materialCode" name="materialCode" type="text" postField="materialCode" suggestFields="materialCode,materialText" 
                    suggestUrl="${rc.getContextPath()}/manage/material/componentSuggest" lookupGroup="materialLookup" remote="${rc.getContextPath()}/manage/material/validateMaterial" warn="<@label key='materialCodeNotExists.M'>物料编号不存在</@label>"/>
                    <a class="btnLook" href="${rc.getContextPath()}/manage/material/componentLookUp?lookupType=radio" rel="materialLookup_dialog" title="<@label key='select.C,materialCode.C'>选择物料</@label>" lookupGroup="materialLookup" ></a>
                </dd>
            </dl>
            <dl>
                <dt><@label key='materialText.C'>物料描述：</@label></dt>
                <dd><input type="text" readonly id="materialLookup.materialText" name="materialText" /></dd>
            </dl>
            <dl class="notnormal">
                <dt><@label key='startTime.C,colon'>开始时间</@label></label></dt>
                <dd>
                    <input type="text" class="required date"  name="startDatetime"  max_Date="{endDatetime}" readonly max_Date="{endDatetime}" dateFmt="yyyy-MM-dd HH:mm:ss" /><a class="inputDateButton" href="javascript:;">选择</a>
                </dd>
            </dl>
            <dl class="notnormal">
                <dt><@label key='endTime.C,colon'>结束时间</@label></dt>
                <dd>
                    <input type="text" class="required date"  name="endDatetime" readonly  min_Date="{startDatetime}" dateFmt="yyyy-MM-dd HH:mm:ss"/><a class="inputDateButton" href="javascript:;">选择</a>
                </dd>
            </dl>
            <dl>
                <dt><@label key='quantity.C,colon'>数量</@label></dt>
                <dd><input type="text" name="quantity" class="required number" min="1" maxlength="15"/></dd>
            </dl>
            <dl>
                <dt><@label key='description.C,colon'>备注</@label></dt>
                <dd><input type="text" name="memo"  maxlength="200"/></dd>
            </dl>
        </fieldset>
    </div>
<div class="panelBar">
    <ul class="toolBar">
        <li><a class="add" target="addPersonnel" title="<@label key='add.B'>添加人员</@label>"><span><@label key="add.B">添加人员</@label></span></a></li>
    </ul>
</div>
<table id="performanceBatchList" class="table canopration" style="width: 100%;" layoutH="236">
    <thead>
        <tr>
            <th width="120"><@label key='personnelCode.C'>人员编号</@label></th>
            <th width="100"><@label key='personnelName.C'>姓名</@label></th>
            <th width="100"><@label key='workCenter.C'>工作中心</@label></th>
            <th width="50"><@label key="opera.C">操作</@label></th>
        </tr>
    </thead>
    <tbody id="performanceBatch">
    </tbody>
</table>
<div class="formBar">
    <ul>
        <li><div class="buttonActive"><div class="buttonContent"><button type="submit"><@label key="save.B">保存</@label></button></div></div></li>
        <li>
            <div class="buttonActiveGrey"><div class="buttonContent"><button type="button" class="close"><@label key="cancel.B">取消</@label></button></div></div>
        </li>
    </ul>
</div>
</form>
<script type="text/javascript">
var performanceBatchDialog = $.pdialog.getCurrent();
var performanceBatchJs = {
        count : 0,
        
        _addPerformance : function() {
            var $tr = $("<tr/>");
            var trId = "tr_"+this.count;
            $tr.attr("id",trId);
            for(var i = 0; i < 4; i++) {
                 $tr.append('<td/>');
            }
            var $tbody = $("#performanceBatchList .gridTbody", performanceBatchDialog).find("table tbody");
            //先填充人员，姓名和操作
            $("td:eq(0)", $tr).append(this._getPersonnelLookUp());
            $("td:eq(1)", $tr).append("<div><input type='text' class='textInput readonly' id='personnelLookup_"+performanceBatchJs.count+".personnelName' readonly /><input type='hidden' name='performances["+performanceBatchJs.count+"].workCenterCode' id='personnelLookup_"+performanceBatchJs.count+".workCenterCode' /></div>");
            $("td:eq(3)", $tr).append("<a title='<@label key='delete.B'>删除</@label>' target='ajax' class='btnDel' onclick='performanceBatchJs._delPerformance(\""+trId+"\");'><@label key='delete.B'>删除</@label></a>");
            $tr.appendTo($tbody);
            $.jTableTool.initGridColumnWidth($tbody.parents('.grid:first'));
            $("a[lookupGroup]", $tr).lookup();
            $("input[suggestFields]", $tr).suggest();
            this.count ++;
        },
        _getPersonnelLookUp : function(){
            return "<div><input class='required look textInput valid'  id='personnelLookup_"+performanceBatchJs.count+".personnelCode' name='performances["+performanceBatchJs.count+"].personnelCode' type='text' postField='personnelCode' suggestFields='personnelCode,personnelName,workCenterCode' callback='performanceBatchJs._setPersonnelMoreInfo'"
            +"suggestUrl='${rc.getContextPath()}/manage/personnel/personnelSuggest' lookupGroup='personnelLookup_"+performanceBatchJs.count+"' remote='${rc.getContextPath()}/manage/personnel/validatePersonnel' />"
            +"<a class='btnLook' href='${rc.getContextPath()}/manage/personnel/personnelLookUp?lookupType=radio' rel='personnel_dialog'  callback='performanceBatchJs._setPersonnelMoreInfo' title='<@label key='select.C,personnelCode.C'>选择人员</@label>' lookupGroup='personnelLookup_"+performanceBatchJs.count+"' ></a></div>"
        },
        _setPersonnelTypeAssign : function(ptas, $tr, currentIndex){
            var selected = $("<select/>");
            selected.attr("name", "performances["+currentIndex+"].personnelTypeCode");
            if(ptas && ptas.length>0){
                for(var i=0; i<ptas.length; i++){
                    var item = ptas[i];
                    if(item && item.personnelTypeCode){
                        var option = $("<option />")
                        option.attr("value",item.personnelTypeCode);
                        option.text(item.typeText);
                        if(item.defaultTypeFlag == 1){
                            option.attr("selected", "selected");
                        }
                    }
                    selected.append(option);
                }
            }
            $tr.find("td:eq(2)").html(selected);
        },
        _setPersonnelMoreInfo : function(args) {
            if(args){
                var currentIndex = args.currentGroup.split("_")[1];//当前tr的坐标
                var personnelCode = args.personnelCode;
                if(personnelCode){
                    $.DWZajax({
                        url:hostUrl +"/personnel/getPersonnelAndType",
                        data:{'personnelCode':personnelCode},
                        callback:function(data){
                            if(data){
                                var $tr = $("#tr_" + currentIndex, $("#performanceBatchList .gridTbody", performanceBatchDialog).find("table tbody"));
                                /* if(data.ptas && data.ptas.length>0){
                                    performanceBatchJs._setPersonnelTypeAssign(data.ptas, $tr, currentIndex);
                                } */
                                $tr.find("td:eq(2)").text(data.workCenterText);
                            }
                        }
                    });
                } 
            }
        },
        _delPerformance: function(_trId){
            var evt = window.event || arguments.callee.caller.arguments[0]
            evt.stopPropagation();
            if(_trId){
            	 var $tbody = $("#performanceBatchList .gridTbody", performanceBatchDialog).find("table tbody");
            	 $tbody.find("tr#"+_trId).remove();
                $.jTableTool.initGridColumnWidth($tbody.parents('.grid:first'));
            }
        },
        _getNextTheDate : function(date){
        	if (date.getTime) {
                return new Date(date.getTime() + 24 * 60 * 60 * 1000);
            } else {
                return new Date(date.parseDate('yyyy-MM-dd HH:mm').getTime() + 24 * 60 * 60 * 1000);
            }
        }
    }
$(function(){
    $("a[target=addPersonnel]", performanceBatchDialog).each(function(){
        var $this = $(this);
        $this.click(function(event){
            performanceBatchJs._addPerformance();
            event.preventDefault();
        })
    });
    var $timeInput = $('[name=startDatetime],[name=endDatetime]', performanceBatchDialog);
    var $date = $('[name=theDate]', performanceBatchDialog);
    $date.on('change', function(){
        if (this.value) {
            $timeInput.attr('minDate', this.value);
            $timeInput.attr('maxDate', performanceBatchJs._getNextTheDate(this.value).formatDate('yyyy-MM-dd'));
            $timeInput.val("");
        } else {
            $timeInput.attr('minDate', today);
            $timeInput.attr('maxDate', performanceBatchJs._getNextTheDate(today).formatDate('yyyy-MM-dd'));
        }
    });
})

</script>